#include<stdio.h>

int SBecomeOver(int a,int o){
	int x[8];
	int k=a;
	int j=0;
	while(k!=0){
		x[j]=k%o;
		k=int(k/o);
		j++;
	}
	int u=1;
	int sum=0;
	for(int z=0;z<=j-1;z++){
		sum+=(x[z]*u);
		u*=10;
	}
	return sum;
}

int main(){
	int n;
	int x;
	int y;
	scanf("%d %d %d",&n,&x,&y);
	int k;
	k=SBecomeOver(n,x);
	int count=0;
	while(k!=0){
		if(k%10==y){
			count++;
		}
		k=int(k/10);
	}
	printf("%d",count);
}
